<?php

/**
 * This is the model class for table "public.page".
 *
 * The followings are the available columns in table 'public.page':
 * @property string $id
 * @property string $revision_id
 * @property string $site_id
 * @property string $template_content_id
 * @property string $css_files
 * @property string $workflow_id
 * @property string $page_data
 * @property string $revised_by
 * @property string $creation_datetime
 * @property string $last_update
 * @property string $js_files
 * @property string $title
 * @property string $alias
 * @property boolean $status
 * @property boolean $allow_cache
 *
 * The followings are the available model relations:
 * @property PageWidget[] $pageWidgets
 * @property PageUrl[] $pageUrls
 * @property Page $revision
 * @property Page[] $pages
 * @property Site $site
 * @property Workflow $workflow
 * @property User $revisedBy0
 * @property TemplateContent $templateContent
 */
class PageBase extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Page the static model class
	 */
	public static function model($className='Page')
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return SITE_TABLE_PREFIX.'page';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('site_id, title', 'required'),
			array('css_files, js_files, title, alias, revision_id, template_content_id, workflow_id, page_data, revised_by, creation_datetime, last_update, status, defaultUrl', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, revision_id, site_id, template_content_id, css_files, workflow_id, page_data, revised_by, creation_datetime, last_update, js_files, title, alias, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'pageWidgets' => array(self::HAS_MANY, 'PageWidget', 'page_id'),
			'pageUrls' => array(self::HAS_MANY, 'PageUrl', 'page_id'),
			'revision' => array(self::BELONGS_TO, 'Page', 'revision_id'),
			'pages' => array(self::HAS_MANY, 'Page', 'revision_id'),
			'site' => array(self::BELONGS_TO, 'Site', 'site_id'),
			'workflow' => array(self::BELONGS_TO, 'Workflow', 'workflow_id'),
			'revisedBy' => array(self::BELONGS_TO, 'User', 'revised_by'),
			'templateContent' => array(self::BELONGS_TO, 'TemplateContent', 'template_content_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'revision_id' => 'Revision',
			'site_id' => 'Site',
			'template_content_id' => 'Template Content',
			'css_files' => 'Css Files',
			'workflow_id' => 'Workflow',
			'page_data' => 'Page Data',
			'revised_by' => 'Revised By',
			'creation_datetime' => 'Creation Datetime',
			'last_update' => 'Last Update',
			'js_files' => 'Js Files',
			'title' => 'Title',
			'alias' => 'Alias',
			'status' => 'Status',
            'allow_cache' => 'Allow cache',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('revision_id',$this->revision_id,true);
		$criteria->compare('site_id',$this->site_id,true);
		$criteria->compare('template_content_id',$this->template_content_id,true);
		$criteria->compare('css_files',$this->css_files,true);
		$criteria->compare('workflow_id',$this->workflow_id,true);
		$criteria->compare('page_data',$this->page_data,true);
		$criteria->compare('revised_by',$this->revised_by,true);
		$criteria->compare('creation_datetime',$this->creation_datetime,true);
		$criteria->compare('last_update',$this->last_update,true);
		$criteria->compare('js_files',$this->js_files,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('alias',$this->alias,true);
		$criteria->compare('status',$this->status);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}